﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using LGSVR.Common;

namespace LGSVR_WEB.sys
{
    public partial class UserActMenuLeft : LGSVR.Common.DataBasePage
    {
        DataTable dt = null;
        DataSet ds = new DataSet();
        DataView dv = new DataView();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "out", "<script>alert('系统超时或服务器故障，请退出重新登录！');window.parent.parent.navigate('../Logout.aspx');</script>");
            }
            if (!IsPostBack)
            BindTree();
        }
        #region 主从表绑定
        private void BindTree()
        {
            int totalRS;
            DataTable dt = GetList("userAct", " ID Asc ", " AND isnull(state,1) <>0 ", 1, int.MaxValue, out totalRS);
            //tvMessageCord.ShowCheckBoxes = TreeNodeTypes.All;
            foreach (DataRow masterRow in dt.Rows)
            {
                //TreeNode masterNode = new TreeNode(masterRow["ActName"].ToString(), masterRow["ActID"].ToString());
                TreeNode masterNode = new TreeNode();
                masterNode.Value = masterRow["ActID"].ToString();
                masterNode.Text = "<span onclick=\"javascript:return refreshpnt('" + masterRow["ActID"].ToString() + "','" + masterRow["ActName"].ToString() + "');\">" + masterRow["ActName"].ToString() + "</span>";
                masterNode.NavigateUrl = "#";
                masterNode.SelectAction = TreeNodeSelectAction.Expand;
              
                tvuserAct.Nodes.Add(masterNode);

                //BindSumTree(masterRow["groupID"].ToString(), masterNode);

            }
           //绑定事件
            //tvuserAct.Attributes.Add("onclick", "postBackByObject()");

        }
        //private void BindTree()
        //{
        //    int totalRS;
        //    dt = GetList("cardGroup", " groupLevel desc ", "", 1, int.MaxValue, out totalRS);
        //    ds.Tables.Add(dt);
        //    dv.Table = ds.Tables[0];

        //    dv.RowFilter = String.Format("parentID='{0}'", "");
        //    foreach (DataRowView drv in dv)
        //    {
        //        TreeNode masterNode = new TreeNode(drv["groupName"].ToString());
        //        masterNode.SelectAction = TreeNodeSelectAction.Expand;
        //        tvMessageCord.Nodes.Add(masterNode);
        //        BindSunTree(drv["groupID"].ToString(), masterNode);
        //        //BindSumTree(masterRow["groupID"].ToString(), masterNode);

        //    }
        //}
        //private void BindSunTree(string strgroupID, TreeNode parentNodes)
        //{
        //    //DataView dv = new DataView();
        //     TreeNode tmpNd = null;
        //     //dv.Table = ds.Tables[0];
        //     dv.RowFilter = String.Format("parentID='{0}'", strgroupID);
        //     if (dv.Count >= 1)
        //     {
        //         foreach (DataRowView drv in dv)
        //         {
        //             tmpNd = new TreeNode();
        //             tmpNd.Text = drv["groupName"].ToString();//节点名称
        //             tmpNd.SelectAction = TreeNodeSelectAction.Expand;
        //             parentNodes.ChildNodes.Add(tmpNd);
        //             //DataView sundv = new DataView();
        //             //sundv.RowFilter = String.Format("parentID='{0}'", drv["groupID"].ToString());
        //             //if (sundv.Count >= 1)
        //             BindSunTree(drv["groupID"].ToString(), tmpNd);
        //             //else
        //             //    BindLeavesTree(drv["groupID"].ToString(), tmpNd);
        //         }
        //     }
        //    else
        //         BindLeavesTree(strgroupID, parentNodes);
        //}
        //private void BindTree(string parentId, TreeNode masterNode)
        //{
        //    int totalRS;
        //    DataTable dt = GetList("cardGroup", " groupLevel desc ", "", 1, int.MaxValue, out totalRS);
        //    //tvMessageCord.ShowCheckBoxes = TreeNodeTypes.All;
        //    foreach (DataRow masterRow in dt.Rows)
        //    {
        //        TreeNode masterNode = new TreeNode(masterRow["groupName"].ToString());
        //        masterNode.SelectAction = TreeNodeSelectAction.Expand;
        //        //tvMessageCord.SelectedNode.Expanded = true;
        //        //tvMessageCord.Nodes.Add(masterNode);

        //        BindSumTree(masterRow["groupID"].ToString(), masterNode);

        //    }
        //}
        //private void BindLeavesTree(string strID, TreeNode TN)
        //{
        //    //dv.RowFilter = String.Format("parentID='{0}'", strID);
        //    // if (dv.Count >= 1)
        //    // {
        //    //     foreach (DataRowView drv in dv)
        //    //     {
        //    //         TreeNode childNode = new TreeNode();
        //    //         childNode.Value = drv["cardID"].ToString();
        //    //         childNode.Text = "<span onclick=\"javascript:return refreshpnt('" + drv["cardID"].ToString() + "');\">" + drv["cardDesc"].ToString() + "</span>";
        //    //         childNode.NavigateUrl = "#";
        //    //         TN.Expanded = false;
        //    //         TN.ChildNodes.Add(childNode);
        //    //     }
        //    // }
        //    int totalRS;
        //    DataTable dst = GetList("cardinfo", " cardType desc ", " AND groupID = '" + strID + "'", 1, int.MaxValue, out totalRS);
        //    foreach (DataRow childRow in dst.Rows)
        //    {
        //        //TreeNode childNode = new TreeNode(childRow["cardID"].ToString(),childRow["cardDesc"].ToString(),"messageInfoList.aspx?cardID=" + childRow["cardID"].ToString(),childRow["cardDesc"].ToString());
        //        TreeNode childNode = new TreeNode();
        //        childNode.Value = childRow["cardID"].ToString();
        //        childNode.Text = "<span onclick=\"javascript:return refreshpnt('" + childRow["cardID"].ToString() + "');\">" + childRow["cardDesc"].ToString() + "</span>";
        //        childNode.NavigateUrl = "#";
        //        //childNode.NavigateUrl = "messageInfoList.aspx?cardID=" + childRow["cardID"].ToString();
        //        TN.Expanded = false;
        //        TN.ChildNodes.Add(childNode);
        //    }
        //}
        #endregion

       // protected void tvMessageCord_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
       // {
       //     e.Node.SelectAction = TreeNodeSelectAction.Expand;
       //     //TreeNode tn = tvMessageCord.SelectedNode;
       //     //tn.Expand();
       // }

       // protected void tvMessageCord_SelectedNodeChanged(object sender, EventArgs e)
       //{
       //     for (int i = 0; i < this.tvMessageCord.Nodes.Count; i++)
       //     {//跌迭根节点
       //         if (this.tvMessageCord.SelectedValue==this.tvMessageCord.Nodes[i].Value )
       //         {//如果选中的是根节点,就展开
       //             this.tvMessageCord.SelectedNode.Expanded = !this.tvMessageCord.SelectedNode.Expanded;
       //         }
               
       //    }
       //}//end tvMessageCord_SelectedNodeChanged
        //treeview收缩其他已点过的节点

        protected void tvUserAct_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
            TreeNodeCollection ts = null;
            if (e.Node.Parent == null)
            {
                ts = ((TreeView)sender).Nodes;
            }
            else
                ts = e.Node.Parent.ChildNodes;
            foreach (TreeNode node in ts)
            {
                if (node != e.Node)
                {
                    node.Collapse();
                }
            }
        }

        //
        protected void tvUserAct_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
        {
            SetChildChecked(e.Node);
        }

        //
        private void SetChildChecked(TreeNode parentNode)
        {
            foreach (TreeNode node in parentNode.ChildNodes)
            {
                node.Checked = parentNode.Checked;

                if (node.ChildNodes.Count > 0)
                {
                    SetChildChecked(node);
                }
            }
        }


  

    }
}
     //TreeNode tNode = new TreeNode();
     //               tNode.Value = row["categoryID"].ToString();
     //               tNode.Text = row["title"].ToString();
     //               tNode.NavigateUrl = "PublicContectPersonList.aspx?categoryID=" + tNode.Value + "";
     //               tNode.Target = "Right";//指向父窗体右边的那个iframe
 
     //               this.tvCategory.Nodes.Add(tNode);
     //               createChildNode(tNode, tNode.Value);
     //        }
 
     //   }
 


     //   /// <summary>
     //   /// 创建子节点
     //   /// </summary>
     //   /// <param name="node"></param>
     //   /// <param name="strParentNo"></param>
     //   private void createChildNode(TreeNode node, string strParentNo)
     //   {
 

     //       DataRow[] Rows = dt.Select("parentID='" + Convert.ToInt32(strParentNo) + "'");
     //       foreach (DataRow row in Rows)
     //       {
     //           TreeNode childNode = new TreeNode();
 
     //           childNode.Value = row["categoryID"].ToString();
     //           childNode.Target = "Right";//指向父窗体右边的那个iframe
     //           childNode.Text = row["title"].ToString();
     //           childNode.NavigateUrl = "PublicContectPersonList.aspx?categoryID=" + childNode.Value + "";
 
     //           node.ChildNodes.Add(childNode);
 
     //           createChildNode(childNode, row["categoryID"].ToString());
 
     //       }
 

     //   }
